package org.laobai.permission.service.impl;

import org.laobai.permission.entity.RoleMenu;
import org.laobai.permission.mapper.RoleMenuMapper;
import org.laobai.permission.service.RoleMenuService;
import org.laobai.permission.struct.PageResult;
import org.laobai.permission.vo.SearchVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Objects;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiusan
 * @since 2021-11-17
 */
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements RoleMenuService {

    @Override
    public PageResult<RoleMenu> page(Integer currPage, Integer pageSize, SearchVO vo) {
        // 分页
        Page<RoleMenu> roleMenuPage = new Page<>(currPage, pageSize);

        // 条件查询
        QueryWrapper<RoleMenu> wrapper = new QueryWrapper<>();

        if (Objects.nonNull(vo)) {
            String keyWord = vo.getKeyWord();
            if (!StringUtils.isEmpty(keyWord)) {
                wrapper.like("name", keyWord);
            }
        }
        roleMenuPage = page(roleMenuPage, wrapper);
        return PageResult.of(roleMenuPage.getRecords(), roleMenuPage.getTotal());
    }

    @Override
    public boolean saveRoleMenu(RoleMenu roleMenu) {
        return save(roleMenu);
    }

    @Override
    public boolean updateRoleMenu(RoleMenu roleMenu) {
        return updateById(roleMenu);
    }

    @Override
    public boolean delById(Long id) {
        return removeById(id);
    }

    @Override
    public boolean delByIds(List<Long> ids) {
        return removeByIds(ids);
    }
}
